#define _CRT_SECURE_NO_WARNINGS 1

#include<stdio.h>

int chengfang(int a, int n)
{
	if (n == 1)
		return a;
	else
	{
		int result = 1;
		for (int i = 0; i < n; i++)
		{
			result = result * a;
		}
		return result;
	}
}
int main()
{
	int n, a;
	int S = 0;
	scanf("%d %d", &n, &a);
	for (int i = 1; i <= n; i++)
	{
		int b = chengfang(a, i);
		S += b;
	}
	printf("%d", S);
	return 0;
}
